<!--
 * @Descripttion: 客人订单
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-28 17:40:28
-->
<template>
    <div class="lb-appointment-order">
        <top-nav></top-nav>
        <div class="page-main">
          <el-row class="page-search-form">
            <el-form @submit.native.prevent :inline="true" :model="searchForm" ref="searchForm">
              <el-form-item label="服务名称" prop="project_name">
                <el-input v-model="searchForm.project_name" placeholder="请输入服务名称"></el-input>
              </el-form-item>
              <el-form-item label="客户名称" prop="name">
                <el-input v-model="searchForm.name" placeholder="请输入客户名称"></el-input>
              </el-form-item>
              <el-form-item label="状态" prop="status">
                <el-select v-model="searchForm.status" placeholder="请选择">
                  <el-option
                    v-for="item in statusOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <lb-button size="medium" type="primary" icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)">{{$t('action.search')}}</lb-button>
                <lb-button size="medium" icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')">{{$t('action.reset')}}</lb-button>
              </el-form-item>
            </el-form>
          </el-row>
          <el-table
            v-loading='loading'
            :data="tableData"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
            style="width: 100%">
              <el-table-column
                prop="id"
                label="服务图片">
                <template slot-scope="scope">
                  <lb-image  :src="scope.row.cover" />
                </template>
              </el-table-column>
              <el-table-column
                prop="project_title"
                label="服务名称">
              </el-table-column>
              <el-table-column
                prop="name"
                label="客户名称">
              </el-table-column>
              <el-table-column
                prop="phone"
                label="客户手机号">
              </el-table-column>
              <el-table-column
                prop="remark"
                label="客户备注">
              </el-table-column>
              <el-table-column
                label="服务时间">
                  <template slot-scope="scope">
                    <p>{{scope.row.sever_time_text.split(' ')[0]}}</p>
                    <p>{{scope.row.sever_time_text.split(' ')[1]}}</p>
                  </template>
              </el-table-column>
              <el-table-column
                label="下单时间">
                  <template slot-scope="scope">
                    <p>{{scope.row.create_time.split(' ')[0]}}</p>
                    <p>{{scope.row.create_time.split(' ')[1]}}</p>
                  </template>
              </el-table-column>
              <el-table-column
                prop="status"
                label="状态">
              </el-table-column>
        </el-table>
        <lb-page
          :batch='false'
          :page='searchForm.page'
          :pageSize='searchForm.limit'
          :total='total'
          @handleSizeChange='handleSizeChange'
          @handleCurrentChange='handleCurrentChange'
          >
        </lb-page>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      searchForm: {
        page: 1,
        limit: 10,
        name: '',
        project_name: '',
        status: ''
      },
      loading: false,
      tableData: [],
      total: 0,
      statusOptions: [
        {
          value: -1,
          label: '全部'
        },
        {
          value: 1,
          label: '未服务'
        },
        {
          value: 2,
          label: '已完成'
        },
        {
          value: 3,
          label: '已过期'
        },
        {
          value: 0,
          label: '已取消'
        }
      ]
    }
  },
  created () {
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    getTableDataList (flag) {
      if (flag === 1) this.searchForm.page = 1
      this.loading = true
      this.$api.getAppointmentRecordList(this.searchForm).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.data
          this.total = res.data.total
          console.log(this.tableData)
        }
      })
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    }
  }
}
</script>

<style lang="scss" scoped>
    .lb-appointment-order{
        width: 100%;

    }
</style>
